﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;



namespace PBRSystem.Coord
{
    public class PBRRayDifferential:PBRRay
    {

        #region Variables
        private bool _hasDifferential;
        private PBRPoint3 _rxOrigin, _ryOrigin;
        private PBRVector3 _rxDirection, _ryDirection;
        #endregion

        #region Reporters
        public bool HasDifferential { get => _hasDifferential; set => _hasDifferential = value; }
        public PBRPoint3 RxOrigin { get => _rxOrigin; set => _rxOrigin = value; }
        public PBRPoint3 RyOrigin { get => _ryOrigin; set => _ryOrigin = value; }
        public PBRVector3 RxDirection { get => _rxDirection; set => _rxDirection = value; }
        public PBRVector3 RyDirection { get => _ryDirection; set => _ryDirection = value; }

        public override bool HasNaNs()
        {
            return base.HasNaNs() &&
                (_hasDifferential && (_rxDirection.HasNaNs() || _ryDirection.HasNaNs() || _rxOrigin.HasNaNs() || _ryOrigin.HasNaNs()));
        }

        #endregion

        #region Contructor

        public PBRRayDifferential()
        {
            _hasDifferential = false;
        }

        public PBRRayDifferential(PBRPoint3 p, PBRVector3 d, float tMax = float.PositiveInfinity, float time = 0.0f) : base(p, d, tMax, time)
        {
            _hasDifferential = false;
        }

        public PBRRayDifferential(PBRRay r):base(r)
        {
            _hasDifferential = false;
        }

        #endregion

        #region Operation
        public void ScaleDifferential(float s)
        {
            _rxOrigin = Origin + (_ryOrigin - Origin) * s;
            _ryOrigin = Origin + (_ryOrigin - Origin) * s;

            _ryDirection = Direction + (_ryDirection - Direction) * s;
            _rxDirection = Direction + (_rxDirection - Direction) * s;

        }
        #endregion
    }
}

